home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / XING Playe22067722001.psc / frmMain.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  2001-06-29  |  22.6 KB  |  722 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
  3. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
  4. Begin VB.Form frmMain 
  5.    Caption         =   "Decoder"
  6.    ClientHeight    =   4815
  7.    ClientLeft      =   60
  8.    ClientTop       =   345
  9.    ClientWidth     =   6105
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   4815
  12.    ScaleWidth      =   6105
  13.    StartUpPosition =   3  'Windows Default
  14.    Begin VB.TextBox Text1 
  15.       Height          =   285
  16.       Left            =   3720
  17.       TabIndex        =   30
  18.       Text            =   "0"
  19.       Top             =   2400
  20.       Width           =   735
  21.    End
  22.    Begin MSComctlLib.Slider slPos 
  23.       Height          =   255
  24.       Left            =   120
  25.       TabIndex        =   29
  26.       Top             =   1440
  27.       Width           =   4695
  28.       _ExtentX        =   8281
  29.       _ExtentY        =   450
  30.       _Version        =   393216
  31.       Max             =   400
  32.       TickFrequency   =   20
  33.    End
  34.    Begin VB.CommandButton btnPause 
  35.       Caption         =   "Pause"
  36.       Height          =   375
  37.       Left            =   2160
  38.       TabIndex        =   14
  39.       Top             =   1920
  40.       Width           =   615
  41.    End
  42.    Begin VB.CommandButton btnBrowseWAV 
  43.       Caption         =   "Browse"
  44.       Height          =   285
  45.       Left            =   3840
  46.       TabIndex        =   5
  47.       Top             =   1080
  48.       Width           =   735
  49.    End
  50.    Begin VB.TextBox txtWAV 
  51.       Height          =   285
  52.       Left            =   120
  53.       TabIndex        =   4
  54.       Text            =   "Text1"
  55.       Top             =   1080
  56.       Width           =   3615
  57.    End
  58.    Begin VB.CommandButton btnStop 
  59.       Caption         =   "Stop"
  60.       Height          =   375
  61.       Left            =   2880
  62.       TabIndex        =   3
  63.       Top             =   1920
  64.       Width           =   615
  65.    End
  66.    Begin VB.CommandButton btnStart 
  67.       Caption         =   "Start"
  68.       Height          =   375
  69.       Left            =   1440
  70.       TabIndex        =   2
  71.       Top             =   1920
  72.       Width           =   615
  73.    End
  74.    Begin VB.TextBox txtMP3 
  75.       Height          =   285
  76.       Left            =   120
  77.       TabIndex        =   1
  78.       Text            =   "Text1"
  79.       Top             =   360
  80.       Width           =   3615
  81.    End
  82.    Begin MSComDlg.CommonDialog cd1 
  83.       Left            =   4320
  84.       Top             =   1560
  85.       _ExtentX        =   847
  86.       _ExtentY        =   847
  87.       _Version        =   393216
  88.    End
  89.    Begin VB.CommandButton btnBrowseMP3 
  90.       Caption         =   "Browse"
  91.       Height          =   285
  92.       Left            =   3840
  93.       TabIndex        =   0
  94.       Top             =   360
  95.       Width           =   735
  96.    End
  97.    Begin VB.Label lblID3V2 
  98.       Caption         =   "Label20"
  99.       Height          =   255
  100.       Left            =   4080
  101.       TabIndex        =   45
  102.       Top             =   4440
  103.       Width           =   1695
  104.    End
  105.    Begin VB.Label lblID3V1 
  106.       Caption         =   "Label19"
  107.       Height          =   255
  108.       Left            =   2400
  109.       TabIndex        =   44
  110.       Top             =   4440
  111.       Width           =   1575
  112.    End
  113.    Begin VB.Label lblGenre 
  114.       Caption         =   "Label19"
  115.       Height          =   255
  116.       Left            =   3240
  117.       TabIndex        =   43
  118.       Top             =   4080
  119.       Width           =   2815
  120.    End
  121.    Begin VB.Label lblComment 
  122.       Caption         =   "Label19"
  123.       Height          =   255
  124.       Left            =   3240
  125.       TabIndex        =   42
  126.       Top             =   3840
  127.       Width           =   2815
  128.    End
  129.    Begin VB.Label lblYear 
  130.       Caption         =   "Label19"
  131.       Height          =   255
  132.       Left            =   3240
  133.       TabIndex        =   41
  134.       Top             =   3600
  135.       Width           =   2815
  136.    End
  137.    Begin VB.Label lblAlbum 
  138.       Caption         =   "Label19"
  139.       Height          =   255
  140.       Left            =   3240
  141.       TabIndex        =   40
  142.       Top             =   3360
  143.       Width           =   2815
  144.    End
  145.    Begin VB.Label lblTitle 
  146.       Caption         =   "Label19"
  147.       Height          =   255
  148.       Left            =   3240
  149.       TabIndex        =   39
  150.       Top             =   3120
  151.       Width           =   2815
  152.    End
  153.    Begin VB.Label lblArtist 
  154.       Caption         =   "Label19"
  155.       Height          =   255
  156.       Left            =   3240
  157.       TabIndex        =   38
  158.       Top             =   2880
  159.       Width           =   2815
  160.    End
  161.    Begin VB.Label Label18 
  162.       Caption         =   "Genre:"
  163.       Height          =   255
  164.       Left            =   2400
  165.       TabIndex        =   37
  166.       Top             =   4080
  167.       Width           =   800
  168.    End
  169.    Begin VB.Label Label17 
  170.       Caption         =   "Comment:"
  171.       Height          =   255
  172.       Left            =   2400
  173.       TabIndex        =   36
  174.       Top             =   3840
  175.       Width           =   800
  176.    End
  177.    Begin VB.Label Label16 
  178.       Caption         =   "Year:"
  179.       Height          =   255
  180.       Left            =   2400
  181.       TabIndex        =   35
  182.       Top             =   3600
  183.       Width           =   800
  184.    End
  185.    Begin VB.Label Label15 
  186.       Caption         =   "Album:"
  187.       Height          =   255
  188.       Left            =   2400
  189.       TabIndex        =   34
  190.       Top             =   3360
  191.       Width           =   800
  192.    End
  193.    Begin VB.Label Label14 
  194.       Caption         =   "Title:"
  195.       Height          =   255
  196.       Left            =   2400
  197.       TabIndex        =   33
  198.       Top             =   3120
  199.       Width           =   800
  200.    End
  201.    Begin VB.Label Label13 
  202.       Caption         =   "Artist:"
  203.       Height          =   255
  204.       Left            =   2400
  205.       TabIndex        =   32
  206.       Top             =   2880
  207.       Width           =   800
  208.    End
  209.    Begin VB.Label Label12 
  210.       Caption         =   "Frames to look for:"
  211.       Height          =   255
  212.       Left            =   2280
  213.       TabIndex        =   31
  214.       Top             =   2400
  215.       Width           =   1335
  216.    End
  217.    Begin VB.Label lblVBR 
  218.       Caption         =   "Label12"
  219.       Height          =   255
  220.       Left            =   1200
  221.       TabIndex        =   28
  222.       Top             =   4320
  223.       Width           =   855
  224.    End
  225.    Begin VB.Label Label11 
  226.       Caption         =   "VBR:"
  227.       Height          =   255
  228.       Left            =   120
  229.       TabIndex        =   27
  230.       Top             =   4320
  231.       Width           =   975
  232.    End
  233.    Begin VB.Label lblFrames 
  234.       Caption         =   "Label11"
  235.       Height          =   255
  236.       Left            =   1200
  237.       TabIndex        =   26
  238.       Top             =   4080
  239.       Width           =   855
  240.    End
  241.    Begin VB.Label Label10 
  242.       Caption         =   "Frames:"
  243.       Height          =   255
  244.       Left            =   120
  245.       TabIndex        =   25
  246.       Top             =   4080
  247.       Width           =   975
  248.    End
  249.    Begin VB.Label lblChannels 
  250.       Caption         =   "Label10"
  251.       Height          =   255
  252.       Left            =   1200
  253.       TabIndex        =   24
  254.       Top             =   3840
  255.       Width           =   855
  256.    End
  257.    Begin VB.Label Label9 
  258.       Caption         =   "Channels:"
  259.       Height          =   255
  260.       Left            =   120
  261.       TabIndex        =   23
  262.       Top             =   3840
  263.       Width           =   975
  264.    End
  265.    Begin VB.Label lblMode 
  266.       Caption         =   "Label9"
  267.       Height          =   255
  268.       Left            =   1200
  269.       TabIndex        =   22
  270.       Top             =   3600
  271.       Width           =   855
  272.    End
  273.    Begin VB.Label Label8 
  274.       Caption         =   "Mode:"
  275.       Height          =   255
  276.       Left            =   120
  277.       TabIndex        =   21
  278.       Top             =   3600
  279.       Width           =   975
  280.    End
  281.    Begin VB.Label lblLayer 
  282.       Caption         =   "Label8"
  283.       Height          =   255
  284.       Left            =   1200
  285.       TabIndex        =   20
  286.       Top             =   2640
  287.       Width           =   855
  288.    End
  289.    Begin VB.Label Label7 
  290.       Caption         =   "Layer:"
  291.       Height          =   255
  292.       Left            =   120
  293.       TabIndex        =   19
  294.       Top             =   2640
  295.       Width           =   975
  296.    End
  297.    Begin VB.Label lblLevel 
  298.       Caption         =   "Label7"
  299.       Height          =   255
  300.       Left            =   1200
  301.       TabIndex        =   18
  302.       Top             =   2400
  303.       Width           =   855
  304.    End
  305.    Begin VB.Label Label6 
  306.       Caption         =   "Level:"
  307.       Height          =   255
  308.       Left            =   120
  309.       TabIndex        =   17
  310.       Top             =   2400
  311.       Width           =   975
  312.    End
  313.    Begin VB.Label lblFrequency 
  314.       Caption         =   "Label6"
  315.       Height          =   255
  316.       Left            =   1200
  317.       TabIndex        =   16
  318.       Top             =   3360
  319.       Width           =   855
  320.    End
  321.    Begin VB.Label lblState 
  322.       Caption         =   "?"
  323.       BeginProperty Font 
  324.          Name            =   "MS Sans Serif"
  325.          Size            =   8.25
  326.          Charset         =   0
  327.          Weight          =   700
  328.          Underline       =   0   'False
  329.          Italic          =   0   'False
  330.          Strikethrough   =   0   'False
  331.       EndProperty
  332.       Height          =   255
  333.       Left            =   120
  334.       TabIndex        =   15
  335.       Top             =   1980
  336.       Width           =   1215
  337.    End
  338.    Begin VB.Label lblTimeElapsed 
  339.       Caption         =   "Label6"
  340.       BeginProperty Font 
  341.          Name            =   "MS Sans Serif"
  342.          Size            =   9.75
  343.          Charset         =   0
  344.          Weight          =   700
  345.          Underline       =   0   'False
  346.          Italic          =   0   'False
  347.          Strikethrough   =   0   'False
  348.       EndProperty
  349.       Height          =   255
  350.       Left            =   3600
  351.       TabIndex        =   13
  352.       Top             =   1980
  353.       Width           =   1095
  354.    End
  355.    Begin VB.Label lblDuration 
  356.       Caption         =   "Label6"
  357.       Height          =   255
  358.       Left            =   1200
  359.       TabIndex        =   12
  360.       Top             =   3120
  361.       Width           =   855
  362.    End
  363.    Begin VB.Label lblBitRate 
  364.       Caption         =   "Label6"
  365.       Height          =   255
  366.       Left            =   1200
  367.       TabIndex        =   11
  368.       Top             =   2880
  369.       Width           =   855
  370.    End
  371.    Begin VB.Label Label5 
  372.       Caption         =   "Frequency:"
  373.       Height          =   255
  374.       Left            =   120
  375.       TabIndex        =   10
  376.       Top             =   3360
  377.       Width           =   975
  378.    End
  379.    Begin VB.Label Label4 
  380.       Caption         =   "Duration:"
  381.       Height          =   255
  382.       Left            =   120
  383.       TabIndex        =   9
  384.       Top             =   3120
  385.       Width           =   975
  386.    End
  387.    Begin VB.Label Label3 
  388.       Caption         =   "Bit Rate:"
  389.       Height          =   255
  390.       Left            =   120
  391.       TabIndex        =   8
  392.       Top             =   2880
  393.       Width           =   975
  394.    End
  395.    Begin VB.Label Label2 
  396.       Alignment       =   2  'Center
  397.       Caption         =   "Destination File (WAV)"
  398.       Height          =   255
  399.       Left            =   120
  400.       TabIndex        =   7
  401.       Top             =   840
  402.       Width           =   4455
  403.    End
  404.    Begin VB.Label Label1 
  405.       Alignment       =   2  'Center
  406.       Caption         =   "Source File (MP3)"
  407.       Height          =   255
  408.       Left            =   120
  409.       TabIndex        =   6
  410.       Top             =   120
  411.       Width           =   4455
  412.    End
  413. Attribute VB_Name = "frmMain"
  414. Attribute VB_GlobalNameSpace = False
  415. Attribute VB_Creatable = False
  416. Attribute VB_PredeclaredId = True
  417. Attribute VB_Exposed = False
  418. Option Explicit
  419. Dim prevState As XA_PlayerState
  420. Private Sub btnBrowseMP3_Click()
  421. Dim ret As Long
  422. Dim hAnalyzer As Long
  423. Dim st As String
  424. Dim wd As Long
  425. Dim fr As Long
  426. 'close input stream if opened
  427. If ReceivedMsg.mInputState = XA_STATE_OPEN Then
  428.     IssuedComm = XA_MSG_COMMAND_INPUT_CLOSE
  429.     If SendCommand(IssuedComm, 0, 0) = False Then GoTo erh
  430. End If
  431. On Local Error GoTo erh
  432. If ret < 0 Then
  433.     MsgBox "Cannot create analyzer object."
  434.     GoTo erh
  435. End If
  436. cd1.CancelError = True
  437. cd1.Filter = "MP3 Files (play/decode)|*.mp3"
  438. cd1.Flags = cdlOFNFileMustExist + cdlOFNLongNames
  439. cd1.ShowOpen
  440. MP3File = cd1.FileName
  441. txtMP3 = MP3File
  442. MP3FileShort = GetShortName(MP3File, True)
  443. btnBrowseWAV.Enabled = True
  444. 'create new analyzer object
  445. ret = xanalyzer_new(hAnalyzer)
  446. Do While hAnalyzer = 0
  447.     DoEvents
  448. wd = 0
  449. fr = Val(Text1.Text)
  450. st = MP3FileShort & Chr(0)
  451. 'GetHeader1
  452. 'GetHeader2
  453. 'this does not work properly with callback
  454. 'initialize track info
  455. 'AnInfo.Track.Album = String(30, Chr(0))
  456. 'AnInfo.Track.Artist = String(30, Chr(0))
  457. 'AnInfo.Track.Comment = String(30, Chr(0))
  458. 'AnInfo.Track.iYear = String(4, Chr(0))
  459. 'AnInfo.Track.Title = String(30, Chr(0))
  460. ret = xanalyzer_process_file(hAnalyzer, st, 0&, 0&, AnInfo, 0&, wd, fr)
  461. Select Case ret
  462. Case Is >= 0
  463.     'ok
  464. Case XANALYZE_ERROR_INTERNAL
  465.     'internal error
  466.     MsgBox "There was an internal error while tried to analize file" & vbNewLine & MP3File, vbCritical + vbOKOnly, "MP3Player"
  467.     GoTo erh
  468. Case XANALYSE_ERROR_OUT_OF_MEMORY
  469.     'outof memory error
  470.     MsgBox "Not enough memory to analize file" & vbNewLine & MP3File, vbCritical + vbOKOnly, "MP3Player"
  471.     GoTo erh
  472. Case XANALYZE_ERROR_NO_SUCH_FILE
  473.     'no such file error
  474.     MsgBox "No file was found with the name:" & vbNewLine & MP3File, vbCritical + vbOKOnly, "MP3Player"
  475.     GoTo erh
  476. Case XANALYZE_ERROR_CANNOT_OPEN
  477.     'cannot open error
  478.     MsgBox "Cannot open file" & vbNewLine & MP3File, vbCritical + vbOKOnly, "MP3Player"
  479.     GoTo erh
  480. Case XANALYZE_ERROR_STOP_CONDITION
  481.     'stop condition met
  482.     MsgBox "Stop condition was met.", vbInformation + vbOKOnly, "MP3Player"
  483. Case XANALYZE_ERROR_WATCHDOG
  484.     'watchdog reached
  485.     MsgBox "Could not find frame start after looking at " & wd & "bytes.", vbInformation + vbOKOnly, "MP3Player"
  486.     GoTo erh
  487. Case Else
  488.     MsgBox "Unknown error occured while trying to analyze file.", vbCritical + vbOKOnly, "MP3Player"
  489.     GoTo erh
  490. End Select
  491. Select Case AnInfo.StreamType.level
  492. Case 0
  493.     lblLevel = "MPEG2.5"
  494. Case 1
  495.     lblLevel = "MPEG1"
  496. Case 2
  497.     lblLevel = "MPEG2"
  498. End Select
  499. lblLayer = AnInfo.StreamType.layer
  500. lblBitRate = AnInfo.StreamType.bitrate
  501. lblFrequency = AnInfo.StreamType.frequency
  502. lblDuration = ConvertMilliSecToTime(AnInfo.Duration)
  503. Select Case AnInfo.StreamType.mode
  504. Case 0
  505.     lblMode = "Stereo"
  506. Case 1
  507.     lblMode = "Joint-Stereo"
  508. Case 2
  509.     lblMode = "Dual Channel"
  510. Case 3
  511.     lblMode = "Mono"
  512. End Select
  513. lblChannels = AnInfo.StreamType.channels
  514. If fr = 0 Then lblFrames = AnInfo.Frames Else lblFrames = ""
  515. 'XANALYZE_REPORT_CHANGING_LEVEL: the MPEG level (MPEG 1 or MPEG 2) is not constant.
  516. 'XANALYZE_REPORT_CHANGING_LAYER: the MPEG layer (1, 2 or 3) is not constant.
  517. 'XANALYZE_REPORT_CHANGING_BITRATE: the bitrate is not constant.
  518. 'XANALYZE_REPORT_CHANGING_FREQUENCY: the sampling frequency is not constant.
  519. 'XANALYZE_REPORT_CHANGING_MODE: the MPEG mode is not constant.
  520. 'XANALYZE_REPORT_CHANGING_CHANNELS: the number of channels (1 for mono, 2 for stereo) is not constant.
  521. If (AnInfo.Flags And XANALYZE_REPORT_CHANGING_BITRATE) = XANALYZE_REPORT_CHANGING_BITRATE Then
  522.     lblVBR.Caption = "True"
  523.     lblVBR = "False"
  524. End If
  525. If (AnInfo.Flags And XANALYZE_REPORT_HAS_ID3V1_HEADER) = XANALYZE_REPORT_HAS_ID3V1_HEADER Then
  526.     lblID3V1 = "Has ID3V1"
  527.     lblID3V1 = "Does not have ID3V1"
  528. End If
  529. If (AnInfo.Flags And XANALYZE_REPORT_HAS_ID3V2_HEADER) = XANALYZE_REPORT_HAS_ID3V2_HEADER Then
  530.     lblID3V2 = "Has ID3V2"
  531.     lblID3V2 = "Does not have ID3V2"
  532. End If
  533. lblArtist = agGetStringFromPointer(AnInfo.Track.Artist)
  534. lblTitle = agGetStringFromPointer(AnInfo.Track.Title)
  535. lblAlbum = agGetStringFromPointer(AnInfo.Track.Album)
  536. lblYear = agGetStringFromPointer(AnInfo.Track.iYear)
  537. lblComment = agGetStringFromPointer(AnInfo.Track.Comment)
  538. lblGenre = AnInfo.Track.Genre
  539.     ret = xanalyzer_delete(hAnalyzer)
  540. 'open input file
  541. MP3FileShort = GetShortName(MP3File, True)
  542. IssuedComm = XA_MSG_COMMAND_INPUT_OPEN
  543. If SendCommand(IssuedComm, 0, 0) = False Then GoTo erh
  544. End Sub
  545. Private Sub btnBrowseWAV_Click()
  546. On Error GoTo erh
  547. If ReceivedMsg.mOutputState = XA_STATE_OPEN Then
  548.     'close output
  549.     IssuedComm = XA_MSG_COMMAND_OUTPUT_CLOSE
  550.     If SendCommand(IssuedComm, 0, 0) = False Then GoTo erh
  551. End If
  552. cd1.CancelError = True
  553. cd1.Flags = cdlOFNLongNames + cdlOFNOverwritePrompt
  554. cd1.Filter = "WAV Files (*.wav)|*.wav"
  555. cd1.ShowSave
  556. WAVFile = cd1.FileName
  557. If Dir(WAVFile, vbNormal) = "" Then
  558.     'create the file
  559.     Open WAVFile For Binary As #1
  560.     Close #1
  561. End If
  562. WAVFileShort = "wav:" & GetShortName(WAVFile, False)
  563. txtWAV.Text = WAVFile
  564. End Sub
  565. Private Sub btnPause_Click()
  566. 'preventing pressing this button again (when player is paused)
  567. '  is done in message processing routine
  568. IssuedComm = XA_MSG_COMMAND_PAUSE
  569. SendCommand IssuedComm, 0, 0
  570. DoEvents
  571. End Sub
  572. Private Sub btnStart_Click()
  573. On Error GoTo erh
  574. 'make sure input file is open
  575. If ReceivedMsg.mInputState = XA_STATE_CLOSED Then
  576.     MsgBox "File to be played is not selected or" & vbNewLine & "could not open the file.", vbCritical + vbOKOnly, "MP3Player"
  577.     Exit Sub
  578. ElseIf ReceivedMsg.mPlayerState = XA_PLAYER_STATE_EOS Then
  579.     'reopen the file
  580.     IssuedComm = XA_MSG_COMMAND_INPUT_OPEN
  581.     If SendCommand(IssuedComm, 0, 0) = False Then GoTo erh
  582. End If
  583. 'prevent from pressing start button when player is playing
  584. Select Case ReceivedMsg.mPlayerState
  585. Case XA_PLAYER_STATE_EOS
  586. Case XA_PLAYER_STATE_PAUSED
  587.     'go to selected position
  588.     IssuedComm = XA_MSG_COMMAND_SEEK
  589.     SendCommand IssuedComm, slPos.Value, slPos.Max
  590.     IssuedComm = XA_MSG_COMMAND_PLAY
  591.     If SendCommand(IssuedComm, 0, 0) = False Then GoTo erh
  592.     Exit Sub
  593. Case XA_PLAYER_STATE_PLAYING
  594.     Exit Sub
  595. Case XA_PLAYER_STATE_STOPPED
  596. End Select
  597. 'open output file:
  598. '   if output file is empty string will play on speakers
  599. '   if not empty then will encode to specified location
  600. '   if filename preceeded with "wav:" then will create wav header
  601. IssuedComm = XA_MSG_COMMAND_OUTPUT_OPEN
  602. If SendCommand(IssuedComm, 0, 0) = False Then GoTo erh
  603. 'set output to stereo - not necessary
  604. IssuedComm = XA_MSG_SET_OUTPUT_CHANNELS
  605. If SendCommand(IssuedComm, XA_OUTPUT_CHANNELS_STEREO, 0) = False Then GoTo erh
  606. 'go to selected position
  607. IssuedComm = XA_MSG_COMMAND_SEEK
  608. SendCommand IssuedComm, slPos.Value, slPos.Max
  609. 'start playing here
  610. IssuedComm = XA_MSG_COMMAND_PLAY
  611. If SendCommand(IssuedComm, 0, 0) = False Then GoTo erh
  612. Select Case ReceivedMsg.mPlayerState
  613. Case XA_PLAYER_STATE_PAUSED
  614.     lblState = "Paused"
  615. Case XA_PLAYER_STATE_PLAYING
  616.     lblState = "Playing"
  617. Case XA_PLAYER_STATE_STOPPED
  618.     lblState = "Stopped"
  619. End Select
  620. prevState = XA_PLAYER_STATE_PLAYING
  621. Do 'loop while playing
  622.     'all messages are accepted by frmPlay
  623.     'we just show the time and position.
  624.     lblTimeElapsed = IIf(ReceivedMsg.mTimecode.mH = 0, "", ReceivedMsg.mTimecode.mH & ":") & Format(ReceivedMsg.mTimecode.mM, "00") & ":" & Format(ReceivedMsg.mTimecode.mS, "00") & "." & Format(ReceivedMsg.mTimecode.mF, "0")
  625.     If ReceivedMsg.mPlayerState <> XA_PLAYER_STATE_PAUSED Then slPos.Value = ReceivedMsg.mPosition.mOffset
  626.     DoEvents
  627. Loop While (ReceivedMsg.mPlayerState = XA_PLAYER_STATE_PLAYING) Or (ReceivedMsg.mPlayerState = XA_PLAYER_STATE_PAUSED)
  628. 'if here then play was stopped or end of stream was reached
  629. slPos.Value = 0
  630. lblTimeElapsed.Caption = "00:00.0"
  631. lblState = "Stopped"
  632. Select Case ReceivedMsg.mPlayerState
  633. Case XA_PLAYER_STATE_PAUSED
  634.     lblState = "Paused"
  635. Case XA_PLAYER_STATE_PLAYING
  636.     lblState = "Playing"
  637. Case XA_PLAYER_STATE_STOPPED
  638.     lblState = "Stopped"
  639. Case XA_PLAYER_STATE_EOS
  640.     lblState = "End Of File"
  641. End Select
  642. 'if were decoding then close the output
  643. If WAVFile <> "" Then
  644.     IssuedComm = XA_MSG_COMMAND_OUTPUT_CLOSE
  645.     SendCommand IssuedComm, 0, 0
  646. End If
  647. Exit Sub
  648. 'necessary to stop - on any error
  649. IssuedComm = XA_MSG_COMMAND_STOP
  650. SendCommand IssuedComm, 0, 0
  651. IssuedComm = XA_MSG_COMMAND_EXIT
  652. SendCommand IssuedComm, 0, 0
  653. End Sub
  654. Private Sub btnStop_Click()
  655. 'preventing pressing this button again (when player is stopped)
  656. '  is done in message processing routine
  657. IssuedComm = XA_MSG_COMMAND_STOP
  658. SendCommand IssuedComm, 0, 0
  659. 'stop it in any case - even if PlayerStop is failed
  660. DoEvents
  661. End Sub
  662. Private Sub Form_Load()
  663. Dim ret As Long
  664. 'initialize player
  665. 'load form that will be a player
  666. Load frmPlay
  667. gHW = frmPlay.hwnd
  668. 'hook this form to process all messages
  669. 'create the player which is hooked to gHW window
  670. ret = player_new(hPlayer, gHW)
  671. 'set user data for the window - don't know why, just in case
  672. SetWindowLong gHW, GWL_USERDATA, hPlayer
  673. 'set high priority for player
  674. ret = player_set_priority(hPlayer, XA_CONTROL_PRIORITY_HIGH)
  675. 'have to preinitialize some vars
  676. ReceivedMsg.mInputState = XA_STATE_CLOSED
  677. ReceivedMsg.mOutputState = XA_STATE_CLOSED
  678. txtMP3.Text = ""
  679. txtWAV.Text = ""
  680. MP3File = ""
  681. WAVFile = ""
  682. 'show equalizer
  683. frmEqualizer.Show 0, frmMain
  684. End Sub
  685. Private Sub Form_Unload(Cancel As Integer)
  686. If hPlayer Then
  687.     'necessary to stop
  688.     control_message_send_N hPlayer, XA_MSG_COMMAND_STOP
  689.     control_message_send_N hPlayer, XA_MSG_COMMAND_EXIT
  690.     player_delete (hPlayer)
  691.     Unhook
  692.     Unload frmPlay
  693. End If
  694. End Sub
  695. Private Sub slPos_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  696. If Button = 1 Then
  697.     'have to pause player
  698.     If ReceivedMsg.mPlayerState = XA_PLAYER_STATE_PLAYING Then
  699.         prevState = XA_PLAYER_STATE_PLAYING
  700.         IssuedComm = XA_MSG_COMMAND_PAUSE
  701.         SendCommand IssuedComm, 0, 0
  702.     Else
  703.         prevState = XA_PLAYER_STATE_STOPPED
  704.     End If
  705. End If
  706. End Sub
  707. Private Sub slPos_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
  708. If Button = 1 Then
  709.     DoEvents
  710.     If prevState = XA_PLAYER_STATE_PLAYING Then
  711.         'start player again
  712.         'go to selected position
  713.         IssuedComm = XA_MSG_COMMAND_SEEK
  714.         SendCommand IssuedComm, slPos.Value, slPos.Max
  715.         'start playing here
  716.         IssuedComm = XA_MSG_COMMAND_PLAY
  717.         SendCommand IssuedComm, 0, 0
  718.         prevState = XA_PLAYER_STATE_PLAYING
  719.     End If
  720. End If
  721. End Sub
  722.